<?php
namespace Admin\Controller;

class TransController extends AdminBaseController
{
   public function index()
    {
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $this->display('trans/index');
    }
    
    public function tranlist(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $page=I('page',1);
        $rows=I('rows',50);
        $start=($page-1)*$rows;
        $domain=I('domain_type_id','');
        if($domain!=''){
            $condi['domain_type_id']=$domain;
        }
        $buyuid=I('buyuid','');
        if($buyuid!=''){
            $condi['buyerid']=$buyuid;
        }
        $selluid=I('selluid','');
        if($selluid!=''){
            $condi['sellerid']=$selluid;
        }
        
        $DomainTranslog = M('DomainTranslog');
        $list = $DomainTranslog->where($condi)->order('createdate desc')->limit($start,$rows)->select();
        $count = $DomainTranslog->where($condi)->count();
        $map=array(
            'rows'=>$list,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }
    
    
    public function trandetails(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $id=I('id','');
        if($id!=''){
            $condi['a.logid']=$id;
        }
        $trandetail=M('DomainTransdetail');
        $list=$trandetail->join(' as a left join dd_domain_type b on a.domain_type_id=b.id')
        ->field('a.id,a.buyerid,a.sellerid,a.domain,a.price,a.creatdate,b.name')->order('a.creatdate desc')->select();
        $this->assign('list',$list);
        $this->display("trans/detail");
    }
    
    public function enstruts(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $categorys=M('DomainType')->select();
        $this->assign("categorys",$categorys);
        $this->display('trans/enstrust');
    }
    
    public function entrustlist(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $page=I('page',1);
        $rows=I('rows',50);
        $start=($page-1)*$rows;
        $domain=I('categrouid','');
        if($domain!=''){
            $condi['a.domain_typeid']=$domain;
        }
        $trantype=I('trantype','');
        if($trantype!=''){
            $condi['a.trans_type']=$trantype;
        }
        $uid=I('uid','');
        if($uid!=''){
            $condi['a.uid']=$uid;
        }
        
        $UserEntrust = M('UserEntrust');
        $list = $UserEntrust->join(" as a left join dd_domain_type b on a.domain_typeid=b.id")
        ->field('a.id,a.trans_type,a.uid,a.trans_mode,a.unit_price,a.dnumber,a.status,a.createdate,a.surplus,b.name')
        ->where($condi)->order('a.createdate desc')->limit($start,$rows)->select();
        $count = $UserEntrust->join(" as a left join dd_domain_type b on a.domain_typeid=b.id")->where($condi)->count();
        $map=array(
            'rows'=>$list,
            'total'=>$count
        );
        $this->ajaxReturn($map,'JSON');
    }
    
}